<template>
  <div class="app-container">
    <el-table
      :key="tableKey"
      v-loading="tableLoading"
      :data="dataElements"
      border
      fit
      highlight-current-row
      style="width: 100%;"
    >
      <el-table-column label="上传服务器名称" prop="name" min-width="190"></el-table-column>
      <el-table-column label="数据缓存数" prop="dataCount" min-width="100"></el-table-column>
      <el-table-column label="告警缓存数" prop="alarmCount" min-width="100"></el-table-column>
      <el-table-column label="操作" align="center" width="280">
        <template slot-scope="{row}">
          <el-button v-permission="['Admin.Remote.Update']" :disabled="managerConnectionStatus!==1" size="mini" type="danger" @click="deleteDataCache(row.id)">清除缓存数据</el-button>
          <el-button v-permission="['Admin.Remote.Update']" :disabled="managerConnectionStatus!==1" size="mini" type="danger" @click="deleteAlarmCache(row.id)">清除缓存告警</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import {
    getShortNorthbound,
    getNorthboundCache,
    deleteDataCache,
    deleteAlarmCache
  } from "@/api/northbound";
  import _ from "lodash";

  export default {
    components: {
    },
    props: {
      managerConnectionStatus: {
        type: Number,
        default: undefined
      }
    },
    data() {
      return {
        isSubmitLoading: false,
        Northbound: [],
        tableLoading: false,
        tableKey: 0,
        dataElements: [],
        itemsChecked: [],
        gatewayId: undefined,
        q: {
          nid: undefined
        }
      };
    },
    computed: {},
    created() {},
    methods: {
      // getShortNorthbound(gatewayId) {
      //   this.gatewayId = gatewayId;
      //   getShortNorthbound(gatewayId).then(result => {
      //     this.Northbound = result;
      //     this.q.nid = result[0].id;
      //     this.getNorthboundCache();
      //   });
      // },
      // northboundClick(id) {
      //   this.q.nid = id;
      //   this.getNorthboundCache();
      // },
      getNorthboundCache(gatewayId) {
        this.gatewayId = gatewayId;
        this.tableLoading = true;
        getNorthboundCache(this.gatewayId).then(result => {
          this.dataElements = result;
          // this.totalCount = result.totalElements;
          this.tableLoading = false;
        });
      },
      indexMethod(index) {
        return index + 1;
      },
      selectionChange(selection) {
        this.itemsChecked = selection;
      },
      deleteDataCache(id) {
        this.$confirm("是否继续?", "确定执行清除数据缓存操作吗？", {
          type: "warning"
        })
          .then(() => {
            deleteDataCache(this.gatewayId, id).then(() => {
              this.getNorthboundCache(this.gatewayId);
              this.$message({ message: "删除成功", type: "success" });
            });
          })
          .catch(() => {
          });
      },
      deleteAlarmCache(id) {
        this.$confirm("是否继续?", "确定执行清除告警缓存操作吗？", {
          type: "warning"
        })
          .then(() => {
            deleteAlarmCache(this.gatewayId, id).then(() => {
              this.getNorthboundCache(this.gatewayId);
              this.$message({ message: "删除成功", type: "success" });
            });
          })
          .catch(() => {
          });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .full-container {
    min-height: calc(100vh - 50px);
  }

  .aside-left {
    margin-bottom: 0;
  }

  .aside-header {
    display: flex;
    align-items: center;
    font-weight: bold;

    &:before {
      content: '';
      display: inline-block;
      margin-right: 5px;
      width: 4px;
      height: 16px;
      background-color: #000000;
    }
  }

  .aside-left-ul {
    margin: 0;
    list-style: none;
    padding-left: 0;

    li {
      position: relative;
      display: flex;
      align-items: center;
      line-height: 40px;
      cursor: pointer;
      border-bottom: 1px dashed #ccc;

      &:before {
        display: inline-block;
        margin-right: 10px;
        content: '';
        width: 10px;
        height: 10px;
        border: 1px solid #000;
      }

      &:after {
        position: absolute;
        top: 12px;
        z-index: 1;
        right: 0;
        content: "\E6E0";
        font-family: 'element-icons' !important;
        speak: none;
        font-style: normal;
        font-weight: normal;
        font-variant: normal;
        text-transform: none;
        line-height: 1;
        vertical-align: baseline;
        display: inline-block;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
      }

      &.active {
        color: #1890ff;
        border-color: #1890ff;
        border-bottom-style: solid;

        &:before {
          background-color: #1890ff;
          border-color: #1890ff;
        }
      }

      & > span {
        display: block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }
  .app-container{
    flex: 1;
    overflow: hidden;
  }
</style>
